var fs = require('fs');
var dbcache = {};
(function init() {
    dbcache['cards'] = JSON.parse(fs.readFileSync('./game_server/jsondb/cards.json'));
})();

function getAllCards() {
    return dbcache['cards'];
}

function getDBCardById(cardid) {
    var quick = dbcache['cards'][cardid - 1];
    if (quick && quick.id == cardid) {
        return quick;
    }

    for (var i = 0; i < dbcache['cards'].length; i++) {
        quick = dbcache['cards'][i];
        if (quick.id == cardid) {
            return quick;
        }
    }
}

module.exports = { getAllCards: getAllCards, getDBCardById: getDBCardById };